<template>
  <div>
    <el-dialog
      title="角色管理"
      :visible.sync="roleshow"
    >
      <el-checkbox-group v-model="checkList">
        <el-checkbox v-for="item in rolelist" :key="item.id" :label="item.id">
          {{ item.name }}
        </el-checkbox>

      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btncancle">取 消</el-button>
        <el-button type="primary" @click="btnok">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getRoleList } from '@/api/setting'
import { userPic, uprole } from '@/api/user'
export default {
  props: {
    roleshow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      rolelist: [],
      a: ''
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    async getRoleList() {
      const res = await getRoleList()
      this.rolelist = res.rows
      console.log(res)
    },
    async getRoleDetail(id) {
      this.a = id
      console.log(this.a)
      const { roleIds } = await userPic(id)
      this.checkList = roleIds
    },
    btncancle() {
      this.checkList = []
      this.$emit('update:roleshow', false)
    },
    btnok() {
      console.log(this.a, this.checkList)
      uprole({
        id: this.a,
        roleIds: this.checkList
      })
      this.$message.success('修改成功')
      this.$emit('update:roleshow', false)
    }
  }
}
</script>
